package com.crm.system.controller.csd.customerManager;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.vo.csd.customerManager.CustomerContactPersonVO;
import com.crm.model.vo.csd.customerManager.CustomerServiceWorkLogVO;
import com.crm.system.service.csd.customerManager.CustomerContactPersonListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangpeng
 * @Date 2021/8/26 14:47
 */
@RestController
@RequestMapping("/csd/customerContactPerson")
public class CustomerContactPersonController {

    @Autowired
    private CustomerContactPersonListService customerContactPersonListService;


    /**
     * selectCustomerContactPersonList
     * 客户列表--查看--联系人管理列表
     * @Author wangpeng
     * @Date 2021/8/31
     * @param pageIndex	 页码
     * @param pageSize	分页大小
     * @param sortName	排序列名字
     * @param sortOrder	排序规则
     * @param customerId  客户ID
     * @param auditStatus  审核状态---0正确;1错误;2未审核
     * @param onTheJobSituation  在职情况 --- 0: 在职; 1: 离职
     * @return
     */
    @PostMapping("/selectCustomerContactPerson")
    public DataResponse selectCustomerContactPersonList(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                               @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                               @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                                               @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                                               String customerId,
                                                               String auditStatus,
                                                               String onTheJobSituation


     ){
        try {
            DhPageInfo<CustomerContactPersonVO> customerContactPersonList = customerContactPersonListService.selectCustomerContactPersonList(pageIndex,pageSize,sortName,sortOrder,customerId,auditStatus,onTheJobSituation);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),customerContactPersonList);
        }catch (Exception e){
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }


    /**
     * 客户列表--查看--联系人管理列表--审核
     * @author wangpeng
     * @param contactPersonId 联系人ID
     */
    @PostMapping("/selectAuditWorkLog")
    public DataResponse selectAuditWorkLog(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                       @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                       @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                                       @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                                       String contactPersonId
    ){
        try {
            DhPageInfo<CustomerServiceWorkLogVO> customerWorkLogList = customerContactPersonListService.selectAuditWorkLog(pageIndex,pageSize,sortName,sortOrder,contactPersonId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),customerWorkLogList);
        }catch (Exception e){
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户列表--查看--联系人管理列表--审核--回显审核状态
     * @author wangpeng
     * @param contactPersonId 联系人ID
     */
    @PostMapping("/selectCustomerContactPersonBycontactPersonId")
    public DataResponse selectCustomerContactPersonBycontactPersonId(String contactPersonId){
        try {
            CustomerContactPersonVO customerContactPerson = customerContactPersonListService.selectCustomerContactPersonBycontactPersonId(contactPersonId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),customerContactPerson);
        }catch (Exception e){
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }




    /**
     * 客户列表--查看--联系人管理列表--审核--修改审核
     * @author wangpeng
     * @param customerId   客户ID
     * @param contactName  联系人
     * @param contactInformation  联系方式
     * @param auditStatus  审核状态
     * @param remarks      备注
     */
    @PostMapping("/updateCustomerContactPersonByCustomerId")
    public DataResponse updateCustomerContactPersonByCustomerId(@RequestParam(value="customerId",required = true) String customerId,
                                                                @RequestParam(value="contactPersonId",required = true) String contactPersonId,
                                                               String contactName,
                                                               String contactInformation,
                                                               Integer auditStatus,
                                                               String remarks

    ){
        try {
            Boolean result =customerContactPersonListService.updateCustomerContactPersonByCustomerId(customerId,contactPersonId,contactName,contactInformation,auditStatus,remarks);
            if (result){
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }catch (Exception e){
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }



}
